package com.daos;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.model.Group;
import com.model.Role;

@Repository
public class GroupDao extends AbstractDao<Group> {

	@SuppressWarnings("unchecked")
	public List<Group> getGroups() {
		return hibernateTemplate.find("from Groups g order by g.name");
	}

	@SuppressWarnings("unchecked")
	public List<Role> getRolesByGroup(int id) {
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append("SELECT  g.roles from Groups g where g.id = ");
		stringBuilder.append(id);
		return hibernateTemplate.find(stringBuilder.toString());
	}

	public Group getGroupById(int id) {
		return (Group) hibernateTemplate.find("from Groups g where g.id = ?",id).get(0);
	}

}
